import type { Module, ActionContext } from 'vuex'
import type { AxiosResponse } from 'axios'
// import type { ClientStateType } from './typings'
import {
  getSystemClientList,
  addSystemClientInfo,
  updateSystemClientInfo,
  deleteSystemClientInfo
} from '~/api/system/systemClient'

const systemClient: Module<Record<string, unknown>, Record<string, unknown>> = {
  namespaced: true,
  state: {},
  getters: {},
  actions: {
    // 获取列表信息
    GetSystemClientList<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        getSystemClientList<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 添加应用
    AddSystemClientInfo<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        addSystemClientInfo<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 修改应用
    UpdateSystemClientInfo<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        updateSystemClientInfo<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 删除应用
    DeleteSystemClientInfo<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        deleteSystemClientInfo<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    }
  }
}

export default systemClient
